package com.thinkfit.jy.dialog;

import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.PopupWindow;

import com.common.lib.activity.BaseActivity;
import com.common.lib.fragment.BaseFragment;
import com.thinkfit.jy.R;
import com.thinkfit.jy.fragment.PersonalDataFragment;

import java.util.ArrayList;

public class ProfilePopupWindow extends PopupWindow implements View.OnClickListener {


    private ArrayList<BaseFragment> mFragments;
    private int mCurrentItem;
    private BaseActivity mActivity;


    public ProfilePopupWindow(BaseActivity activity, View anchor) {
        super(LayoutInflater.from(activity).inflate(R.layout.activity_user_profile, null),
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT, true);
        mActivity = activity;
        setTouchable(true);
        setFocusable(true);
        setOutsideTouchable(true);
        setBackgroundDrawable(new ColorDrawable(0));
        update();
        backgroundAlpha(0.4f);
        setAnimationStyle(android.R.style.Animation_Translucent);
        setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss() {
                backgroundAlpha(1f);
            }
        });
        showAsDropDown(anchor);

        mCurrentItem = 0;
        mFragments = new ArrayList<>();
        mFragments.add(new PersonalDataFragment());
        mFragments.add(new PersonalDataFragment());
        mFragments.add(new PersonalDataFragment());
//        ViewPager viewPager = getContentView().findViewById(R.id.viewPager);
//        LogUtil.LogE(viewPager);
//        viewPager.setAdapter(new FragmentPagerAdapter(mActivity.getSupportFragmentManager()) {
//            @NonNull
//            @Override
//            public Fragment getItem(int position) {
//                return mFragments.get(position);
//            }
//
//            @Override
//            public int getCount() {
//                return mFragments.size();
//            }
//
//        });
//        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
//            @Override
//            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
//
//            }
//
//            @Override
//            public void onPageSelected(int position) {
//                mCurrentItem = position;
//            }
//
//            @Override
//            public void onPageScrollStateChanged(int state) {
//
//            }
//        });
//        viewPager.setCurrentItem(mCurrentItem);
    }

    private void backgroundAlpha(float bgAlpha) {
        WindowManager.LayoutParams lp = mActivity.getWindow().getAttributes();
        lp.alpha = bgAlpha;
        mActivity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        mActivity.getWindow().setAttributes(lp);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        }
    }
}
